package com.example.juctest.queue_test;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.SynchronousQueue;

public class SynchronousQueueTest {
    public static void main(String[] args) throws InterruptedException {
        SynchronousQueue<String> strings=new SynchronousQueue<>();
        new Thread(()->{
            try {
                Thread.sleep(1000);
                strings.put("1");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
        new Thread(()->{
            try {
                Thread.sleep(1000);
                strings.put("2");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
        new Thread(()->{
            try {
                Thread.sleep(1000);
                strings.put("3");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
        String take = strings.take();
        System.out.println(take);
        String take2 = strings.take();
        System.out.println(take2);
        String take3 = strings.take();
        System.out.println(take3);
    }

    public static class Main{

        public static void main(String[] args) throws InterruptedException {
            ArrayBlockingQueue<Integer> queue=new ArrayBlockingQueue<>(10);
            boolean offer = queue.offer(1);
            queue.offer(2);
            queue.put(3);
            System.out.println("queue = " + queue);
        }

        public static void addElement(int i){

        }
    }
}
